home *** CD-ROM | disk | FTP | other *** search
- /* $Id: 3Dbstype.h 1.11 1995/10/30 05:54:20 PIERRE Exp $ */
- /*****************************************************************************\
- * *
- * 3DBsType.h - Basic 3D types definition *
- * *
- * Common to EVX and COM interfacing. *
- * Uses QuickMath unless qUsesQuickMath is false. *
- * *
- * Copyright (c) 1995, Ray Dream, Inc. All rights reserved. *
- * *
- \*****************************************************************************/
-
- #ifndef __3DBSTYPE__
- #define __3DBSTYPE__
-
- #if 0
- #if !defined(ULONG) && !defined(BASETYPES) // PF: ULONG is defined in COM headers but not in the EVX ones
- #define ULONG unsigned long
- typedef ULONG *PULONG;
- typedef unsigned short USHORT;
- typedef USHORT *PUSHORT;
- typedef unsigned char UCHAR;
- typedef UCHAR *PUCHAR;
- typedef char *PSZ;
- #define BASETYPES
- #endif
- #endif
-
-
- // QuickMath. We use QMath.h by default
- // If you do not want to use QuickMath, define qUsesQuickMath and define the NUM3D;
- // VECTOR2D, and VECTOR3D types before including this file.
- #ifndef qUsesQuickMath
- #define qUsesQuickMath 1
- #endif
-
- #if qUsesQuickMath
- #include "QMath.h"
- typedef QuickFix NUM3D;
- typedef QuickFixVector2 VECTOR2D;
- typedef QuickFixVector3 VECTOR3D;
- #endif
-
-
- struct I3DShInstance;
-
- /** Constants **************************************************/
-
- //-- Shading Level
- enum ShadingLevel {
- kShLvlNoChanges=-1, // No Changes - Use renderer’s default shading level
- kShLvlInvisible=0, // Invisible - Do not render
- kShLvlBBox=1, // Render bounding box only
- kShLvlWireFrame=2, // Wireframe
- kShLvlPreview=3, // Preview Shading - Fast and crude shading
- kShLvlFullShading=4 // Full Shading
- };
-
-
- /** Base types defines **************************************************/
- typedef unsigned char BOOLEAN;
-
- #ifndef NULL
- #define NULL 0
- #endif
-
- #ifndef TRUE
- #define TRUE 1
- #endif
-
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- /** 3D types defines **************************************************/
-
- #ifndef BOX2D
- typedef struct BOX2D{
- VECTOR2D fMin;
- VECTOR2D fMax;
- } BOX2D;
- #define BOX2D BOX2D
- #endif
-
- #ifndef BOX3D
- typedef struct BOX3D {
- VECTOR3D fMin;
- VECTOR3D fMax;
- } BOX3D;
- #define BOX3D BOX3D
- #endif
-
- // The i, j and k vectors
- // can be considered as the unit vectors of the Local System,
- // and the fix, fiy,... values as they coordinates in the
- // Global Coordinates System.
- typedef struct MATRIX3D {
- NUM3D fix, fjx, fkx,
- fiy, fjy, fky,
- fiz, fjz, fkz;
- } MATRIX3D;
-
-
- // Matrix 3 x 3 + translation
- typedef struct TRANSFORM3D {
- MATRIX3D fR; // Rotation 3 x 3 matrix
- VECTOR3D fT; // Translation
- } TRANSFORM3D;
-
- // Tree transformation
- typedef struct TREETRANSFORM3D {
- MATRIX3D fR; // Rotation 3 x 3 matrix
- VECTOR3D fT; // Translation
- NUM3D fS; // Uniform scaling
- } TREETRANSFORM3D;
-
- typedef struct COLOR3D {
- long Mode; // Color model. 0=RGB, 1=CMYK
- NUM3D R; // Red or Cyan
- NUM3D G; // Green or Magenta
- NUM3D B; // Blue or Yellow
- NUM3D A; // N/A or Black
- } COLOR3D;
-
- typedef struct RECT3D {
- short top;
- short left;
- short bottom;
- short right;
- } RECT3D;
-
- typedef struct VERTEX3D {
- VECTOR3D fVertex; // x, y, z vertex coordinates
- VECTOR3D fNormal; // Nx, Ny, Nz normal values at that vertex
- NUM3D fu,fv; // Texture u,v values at that vertex
- } VERTEX3D;
-
- typedef struct FACET3D{
- VERTEX3D fVertices[3]; // The facet three vertices
- short fUVSpace; // UV Space ID this facet belongs to
- short fReserved; // Reserved - 0
- } FACET3D;
-
- typedef struct PATCH3D{
- VECTOR3D fVertices[4][4]; // The patch 16 vertices
- NUM3D fu[2]; // u values at the patch boundaries
- NUM3D fv[2]; // v values at the patch boundaries
- short fUVSpace; // UV Space ID this patch belongs to
- short fReserved; // Reserved - 0
- } PATCH3D;
-
-
-
- /** Shading defines **************************************************/
-
- typedef struct ShadingFlags{
- BOOLEAN fCallOnce; // Constant Shader: The shader needs to be called only once for the whole object or shading area
- BOOLEAN fNeedsColor; // Needs Color - Not used
- BOOLEAN fNeedsPoint; // Needs surface point in Global Coordinates
- BOOLEAN fNeedsNormal; // Needs surface Normal in Global Coordinates
- BOOLEAN fNeedsIsoU; // Needs U iso-parametric vector in Local Coordinates
- BOOLEAN fNeedsIsoV; // Needs V iso-parametric vector in Local Coordinates
- BOOLEAN fNeedsUV; // Needs u,v texture values
- BOOLEAN fNeedsPointLoc; // Needs surface point in Local Coordinates
- BOOLEAN fNeedsNormalLoc; // Needs surface Normal in Local Coordinates
- BOOLEAN fNeedsPixelRatio; // Needs Pixel Ratio - Not used yet - Future use
- BOOLEAN fChangesNormal; // The shader changes the Normal. The new Normal will have to be read in ShadingOut::fChangedNormal
- } ShadingFlags;
-
- typedef struct ShadingIn {
- COLOR3D fColor; // Color - Not used - For future use
- VECTOR3D fPoint; // Surface point in Global Coordinates
- VECTOR3D fNormal; // Surface Normal in Global Coordinates
- VECTOR3D fIsoU; // U iso-parametric vector in Local Coordinates
- VECTOR3D fIsoV; // V iso-parametric vector in Local Coordinates
- VECTOR2D fUV; // u,v texture values
- unsigned long fUVSpaceID; // UV Space ID
- VECTOR3D fPointLoc; // Surface point in Local Coordinates
- VECTOR3D fNormalLoc; // Surface Normal in Local Coordinates
- NUM3D fPixelRatio; // Pixel Ratio - Not used - For future use
- } ShadingIn;
-
- typedef struct ShadingOut{
- COLOR3D fColor; // Diffuse Color (Kd)
- COLOR3D fSpecularColor; // Specular Color (Ks)
- NUM3D fSpecularSize; // Specular highlight size (Ns)
- NUM3D fAmbient; // Ambient factor (Fa)
- NUM3D fLambert; // Diffuse factor (Fd)
- COLOR3D fReflection; // Reflectivity (Rx)
- COLOR3D fTransparency; // Transparency (Tx)
- NUM3D fRefractiveIndex; // Refraction index (Nr)
- COLOR3D fGlow; // Glow color
- VECTOR3D fChangedNormal; // Changed Normal in Global Coordinates
- } ShadingOut;
-
- typedef struct UVSpaceInfo {
- unsigned long fID; // UV Space ID
- VECTOR2D fMin; // UV Space minimum boundaries
- VECTOR2D fMax; // UV Space maximum boundaries
- BOOLEAN fWraparound[2]; // Tells is the UV Space is closed in the U or V direction
-
- //-- Flat surfaces handling:
- BOOLEAN fIsFlatSurface; // TRUE if the object is a flat surface only
- // for xyz to uv
- VECTOR2D fUVOffset;
- VECTOR3D fProjU;
- VECTOR3D fProjV;
- // for uv to xyz
- VECTOR3D fOffset;
- VECTOR2D fProjX;
- VECTOR2D fProjY;
- VECTOR2D fProjZ;
- } UVSpaceInfo;
-
- typedef struct ShadingInOut{
- ShadingIn* fIn; // Shading input parameters
- ShadingOut* fOut; // Shading output parameters
- UVSpaceInfo* fUVInfo; // UV Space information
- unsigned long fCurrentCompletionMask; // Internal flags for shaders. Must be set to 0x7F before calling DoShade
- } ShadingInOut;
-
- typedef struct ShadingElemRect { // Rectangle in a Shading Element.
- NUM3D fTop;
- NUM3D fLeft;
- NUM3D fBottom;
- NUM3D fRight;
- } ShadingElemRect;
-
- // Shading Element:
- // A Shading Element defines an area of Shading on an Object surface.
- // The area is defined in the surface UV Space.
- // fBBox and fShaderBox define the same rectangle in two different systems. fBBox is
- // in the UV Space, and thus defines the extent of the Shading Element on the Object
- // surface. fShaderBox defines the boundaries of the UV values that will be passed to
- // the Shader. Therefore, moving or rezising the Shading Element on the object surface
- // will not change the shading inside the Shading Element (provided that the Shader bases
- // its calculations on the UV values. Otherwise the discussion is pointless).
- typedef struct ShadingElem {
- ShadingElemRect fBBox; // Extent of the Shading Element in the UV Space
- ShadingElemRect fShaderBox; // Extent of the Shading Element as seen by the shader
- NUM3D fOpacity; // Opacity of the Shading Element vs. whatever other Shader Elements may be under
- } ShadingElem;
-
- /*****************************************************************************\
- * Lighting Model: *
- * *
- * -- -- *
- * \ \ Ns *
- * Color = Fa*Kd*Ia + / Fd*Kd*Ii(Li.N) + / Ks*Ii*(Ri.N) + Rx*(reflected color) + Tx*(transmitted color)
- * --i --i *
- * *
- * With: *
- * Ia: Ambient light color *
- * Ii: Color of the light source #i *
- * Li: Unit vector pointing from the surface point to light source #i *
- * N : Surface Normal *
- * Ri: Unit vector giving the reflection direction of the light source #i *
- * *
- * V1.V2 is a scalar product between 2 vectors: *
- * V1.V2 = V1.x*V2.x + V1.y*V2.y + V1.z*V2.z *
- * *
- * Refracted ray direction is computed using Snell's law: *
- * Nr1 * Sinus(alpha1) = Nr2 * Sinus(alpha2) *
- * *
- * *
- \*****************************************************************************/
-
-
- /** Ray-tracing defines **************************************************/
-
- typedef struct Ray3D{
- VECTOR3D fOrigin; // Origin of the ray
- VECTOR3D fDirection; // Direction of the ray
- NUM3D fFocalPoint; // ???
- NUM3D fAngle; // ???
- NUM3D fWidthAtFocal; // ???
- } Ray3D;
-
- typedef struct RayHit3D{
- VECTOR3D fPosition; // Intersection point in Global Coordinates
- VECTOR3D fNormal; // Normal at that point in Global Coordinates
- VECTOR2D fUV; // (u,v) texture values at that point
- NUM3D ft; // t parameter along the ray: fPosition = RayOrigin + t * RayDirection
- VECTOR3D fIsoU; // Isoparametric U vector in the Object Local Coordinates
- VECTOR3D fIsoV; // Isoparametric V vector in the Object Local Coordinates
- void* fPrivate1; // Private data for renderer.
- void* fPrivate2; // Private data for renderer
- void* fPrivate3; // Private data for renderer
- BOOLEAN fShouldSetUV; // TRUE if fUV should be set
- BOOLEAN fShouldSetIsoUV; // TRUE if fIsoU and fIsoV should be set
- BOOLEAN fHasSetPosition; // TRUE if fPosition was set
- BOOLEAN fHasSetNormal; // TRUE if fNormal was set
- BOOLEAN fHasSetUV; // TRUE if fUV was set
- BOOLEAN fHasSetIsoUV; // TRUE if fIsoU and fIsoV were set
- } RayHit3D;
-
- typedef BOOLEAN (*FilterHitProc) (I3DShInstance* instance);
-
- typedef struct RayHitParameters {
- NUM3D tmin;
- NUM3D tmax;
- BOOLEAN fShouldSetS;
- BOOLEAN fShouldSetUV;
- BOOLEAN fZBShading;
- BOOLEAN fNoGrid;
- void *fFilterInstance;
- } RayHitParameters;
-
- typedef struct HitInfo {
- //-- Output data:
- I3DShInstance* fInstance; // Instance that was hit by the ray
- VECTOR2D fUV; // (u,v) texture values at the intersection point
- unsigned long fUVSpaceID; // UV Space ID
- VECTOR3D fPosition; // Intersection point in Global Coordinates
- VECTOR3D fNormal; // Normal at that point in Global Coordinates
- COLOR3D fColor; // Rendered final color (all lighting and shading included)
- NUM3D fAlpha; // Alpha-channel value
- unsigned long fIndex; // Instance unique index
- NUM3D fDistance; // Distance from the point of view to the intersection point
-
- //-- Input flags:
- BOOLEAN fNeedsColor; // Needs fColor
- BOOLEAN fNeedsDistance; // Needs fDistance
- BOOLEAN fNeedsPosition; // Needs fPosition
- BOOLEAN fNeedsNormal; // Needs Normal
- BOOLEAN fNeedsAlpha; // Needs Alpha
- BOOLEAN fNeedsIndex; // Needs Intance index
- BOOLEAN fNeedsUV; // Needs (u,v) values
- BOOLEAN fZBShading; // Ask for Z-Buffer-like shading: no transparencies, no reflections and no shadows
- FilterHitProc fFilterInstanceProc; //Filterproc for instances. used only in fast hit mode when fNeedsColor is false
- } HitInfo;
-
- typedef void (*RayHitCallback)(Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, void* privData);
- typedef void (*RayTraceCallback)(HitInfo* hitInfo, void* privData);
-
-
- //*********************************************************************************
-
- class SDGraphicDevice;
- struct I3DShInstance;
- typedef void (*EnumPatchesCallback) (PATCH3D* patch, void* privData);
- typedef void (*EnumFacetsCallback) (FACET3D* facet, void* privData);
-
- typedef struct GBufferData {
- void* data;
- long channelBits;
- long channelOffsetBits;
- long columnBits;
- long rowBits;
- short nbrChannels;
- } GBufferData;
-
- typedef struct GBuffer {
- GBufferData color;
- GBufferData distance;
- GBufferData position;
- GBufferData normal;
- GBufferData alpha;
- GBufferData index;
- GBufferData surface;
- } GBuffer;
-
- typedef struct LightTraceElement {
- VECTOR3D fPoint1;
- VECTOR3D fVector1;
- VECTOR3D fPoint2;
- VECTOR3D fVector2;
- } LightTraceElement;
-
-
- //****** Parameter blocks for building extrusions ******************************
-
- #ifdef __cplusplus
- class I3DShCrossSection;
- #else
- typedef void* I3DShCrossSection;
- #endif
-
-
- typedef struct Path3DPoint {
- VECTOR3D fVertex; // Vertex
- // Fill these only if using envelopes:
- VECTOR3D fTopEnv; // Envelope: top curve on right wall
- VECTOR3D fBotEnv; // Envelope: bottom curve on right wall
- VECTOR3D fLeftEnv; // Envelope: left curve on floor
- VECTOR3D fRightEnv; // Envelope: right curve on floor
- } Path3DPoint;
-
- typedef struct ExtrusionHeaderPB {
- Path3DPoint f3DPathPrevControl1; // Don't fill this if 1st section
- Path3DPoint f3DPathPrevControl2; // Don't fill this if 1st section
- VECTOR3D f3DPathVertex; // Put 0 in x and z unless you know what you're doing
- BOOLEAN fFill;
- BOOLEAN fSkinToNext;
- } ExtrusionHeaderPB;
-
- typedef struct ExtrusionPB { // Adding a non-automatic cross-section
- ExtrusionHeaderPB fHeader;
- //-- Specific parameters:
- I3DShCrossSection* fCrossSection;
- NUM3D fTwisting; // Twisting angle
- } ExtrusionPB;
-
- typedef struct ExtrusionAutoPB { // Adding an automatic cross-section
- ExtrusionHeaderPB fHeader;
- //-- Specific parameters:
- NUM3D fTopScaling;
- NUM3D fBotScaling;
- NUM3D fLeftScaling;
- NUM3D fRightScaling;
- } ExtrusionAutoPB;
-
- // Envelope flags:
- enum { kExtrFree=0, // Free Envelope
- kExtrSym=1, // Symetrical Envelope
- kExtrSemiSym=6}; // Semi-symetrical Envelope
-
-
- //-- Old EVX naming compatibility box - to become obsolete in the near future
- #ifdef __EVXCOMPATIBILITY__
- #define MTRay Ray3D
- #define MTRayHit RayHit3D
- #define THitInfo HitInfo
- #define MTShFlags ShadingFlags
- #define TShadingIn ShadingIn
- #define TShadingOut ShadingOut
- #define TShadingElem ShadingElem
- #define TUVSpaceInfo UVSpaceInfo
- #define MTShadingIO ShadingInOut
- #define RayHitParams RayHitParameters
- #ifndef TINSTANCE
- #ifndef __cplusplus
- #define TINSTANCE void
- #else
- class TInstance;
- #define TINSTANCE TInstance
- #endif
- #endif
- #define ShRect ShadingElemRect
- #define TRANSCALE TREETRANSFORM3D
- #define TRANSFORM TRANSFORM3D
- #define MAT33 MATRIX3D
- #define FIXED NUM3D
- #define VECTOR2 VECTOR2D
- #define VECTOR3 VECTOR3D
- #define TVertex VERTEX3D
- #define TFacette FACET3D
- #define TPatch PATCH3D
- #define COLOR COLOR3D
- #define RECT RECT3D
- #define TLightTraceElement LightTraceElement
-
-
- #ifdef _WIN31
- #define RDXAPI __cdecl __loadds
- #define RDXAPITYPE __cdecl
- #else
- #define RDXAPI
- #define RDXAPITYPE
- #define __cdecl
- #define __loadds
- #endif
-
- #endif // __EVXCOMPATIBILITY__
-
- #endif
-
-